# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Unbundle tree-sitter grammars (https://github.com/lapce/lapce/issues/486)
#
pkgname=lapce
pkgver=0.1.2
pkgrel=0
pkgdesc="Lightning-fast and Powerful Code Editor written in Rust"
url="https://lapce.dev"
# ppc64le: ring crate fails to build
# armhf, armv7, x86: wasmer-vm crate fails to build (unsupported platform)
# riscv64, s390x: blocked by rust/cargo
arch="aarch64 x86_64"  # limited by rust/cargo
license="Apache-2.0"
makedepends="
	cargo
	cmd:patchelf
	fontconfig-dev
	freetype-dev
	gtk+3.0-dev
	libgit2-dev
	libssh2-dev
	libxcb-dev
	libxfixes-dev
	libxkbcommon-dev
	openssl-dev
	python3
	vulkan-loader-dev
	wayland-dev
	"
subpackages="$pkgname-proxy"
source="https://github.com/lapce/lapce/archive/v$pkgver/lapce-$pkgver.tar.gz
	$pkgname.desktop
	"
options="!check"  # no tests provided

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO="true"
export CARGO_PROFILE_RELEASE_OPT_LEVEL=2

export LIBSSH2_SYS_USE_PKG_CONFIG=1  # use system libssh2

prepare() {
	default_prepare

	sed -i 's/"vendored-openssl"//' ./*/Cargo.toml

	# --locked is intentionally omitted to update Cargo.lock after the update above.
	cargo fetch
}

build() {
	cargo build --release --frozen

	# Add missing vulkan dependency.
	patchelf --add-needed libvulkan.so.1 target/release/lapce
}

package() {
	install -D -m755 target/release/lapce -t "$pkgdir"/usr/bin/
	install -D -m755 target/release/lapce-proxy -t "$pkgdir"/usr/bin/

	install -D -m644 "$srcdir"/$pkgname.desktop -t "$pkgdir"/usr/share/applications/
	install -D -m644 extra/images/logo.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/$pkgname.svg
}

proxy() {
	pkgdesc="Remote proxy server for the Lapce editor"

	amove usr/bin/lapce-proxy
}

sha512sums="
4be0d29d20dad1ffdae474ba35f8fb7b711403019cdc9d76223e8630d492bd2f311b56ed5a5cf2dd37ceef234ff6e8629fcb46518edfeaaf4c1b821498870cdc  lapce-0.1.2.tar.gz
4daa808a02a3570d322d0d5a5f8a82323400cf20c4e167f9e1388f9f51e933965ce9076a0c7f1849b7888a732d30b1719eceabc6a187059484d0ae2496cb2870  lapce.desktop
"
